<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>tbox</title>
  <link rel="icon" href="/assets/img/favicon.ico">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta name="description" content="Description">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <link href="//cdn.jsdelivr.net/npm/github-markdown-css@4.0.0/github-markdown.min.css" rel="stylesheet">
  <style>
	.markdown-body {
		box-sizing: border-box;
		min-width: 200px;
		max-width: 980px;
		margin: 0 auto;
		padding: 45px;
	}

	@media (max-width: 767px) {
		.markdown-body {
			padding: 15px;
		}
	}
  </style>
</head>
<body>
<article class="markdown-body">
<h4>This is a mirror page, please see the original page: </h4><a href="https://tboox.io/#/getting_started">https://tboox.io/#/getting_started</a>
</br>
    <h2 id="introduction">Introduction (<a href="/mirror/zh-cn/getting_started.html">中文</a>)</h2>
<p>TBOX is a glib-like cross-platform C library that is simple to use yet powerful in nature.</p>
<p>The project focuses on making C development easier and provides many modules (.e.g stream, coroutine, regex, container, algorithm ...),<br>so that any developer can quickly pick it up and enjoy the productivity boost when developing in C language.</p>
<p>It supports the following platforms:</p>
<ul>
<li>Windows</li>
<li>Macosx</li>
<li>Linux</li>
<li>Android</li>
<li>iOS</li>
</ul>
<p>And it provides many compiling options using <a href="https://github.com/xmake-io/xmake">xmake</a>:</p>
<ul>
<li>Release: Disable debug information, assertion, memory checking and enable optimization.</li>
<li>Debug: Enable debug information, assertion, memory checking and disable optimization.</li>
<li>Small: Disable all extensional modules and enable space optimization.</li>
<li>Micro: compiling micro library (~64K) for the embed system.</li>
</ul>
<p>If you want to know more, please refer to:</p>
<ul>
<li><a href="https://tboox.org">HomePage</a></li>
<li><a href="https://tboox.io/#/getting_started">Documents</a></li>
<li><a href="https://github.com/tboox/tbox">Github</a></li>
<li><a href="https://gitee.com/tboox/tbox">Gitee</a></li>
</ul>
<h2 id="features">Features</h2>
<h4 id="thestreamlibrary">The stream library</h4>
<ul>
<li>Supports file, data, http and socket source</li>
<li>Supports the stream filter for gzip, charset and...</li>
<li>Implements stream transfer</li>
<li>Implements the static buffer stream for parsing data</li>
<li>Supports coroutine and implements asynchronous operation</li>
</ul>
<h4 id="thecoroutinelibrary">The coroutine library</h4>
<ul>
<li>Provides high-performance coroutine switch(refer to <a href="https://tboox.org/2016/10/28/benchbox-coroutine/">reports</a>)</li>
<li>Supports arm, arm64, x86, x86_64 ..</li>
<li>Provides channel interfaces</li>
<li>Provides semaphore and lock interfaces</li>
<li>Supports io socket and stream operation in coroutine</li>
<li>Provides some io servers (http ..) using coroutine</li>
<li>Provides stackfull and stackless coroutines</li>
<li>Support epoll, kqueue, poll, select and IOCP</li>
</ul>
<h4 id="thedatabaselibrary">The database library</h4>
<ul>
<li>Supports mysql and sqlite3 database and enumerates data using the iterator mode</li>
</ul>
<h4 id="thexmlparserlibrary">The xml parser library</h4>
<ul>
<li>Supports DOM and SAX mode and Supports xpath</li>
</ul>
<h4 id="theserializationanddeserializationlibrary">The serialization and deserialization library</h4>
<ul>
<li>Supports xml, json, bplist, xplist, binary formats</li>
</ul>
<h4 id="thememorylibrary">The memory library</h4>
<ul>
<li>Implements some memory pools for optimizing memory</li>
<li>Supports fast memory error detecting. it can detect the following types of bugs for the debug mode:<ul>
<li>out-of-bounds accesses to heap and globals</li>
<li>use-after-free</li>
<li>double-free, invalid free</li>
<li>memory leaks</li>
</ul>
</li>
</ul>
<h4 id="thecontainerlibrary">The container library</h4>
<ul>
<li>Implements hash table, single list, double list, vector, stack, queue<br>and min/max heap. Supports iterator mode for algorithm</li>
</ul>
<h4 id="thealgorithmlibrary">The algorithm library</h4>
<ul>
<li>Uses the iterator mode</li>
<li>Implements find, binary find and reverse find algorithm</li>
<li>Implements sort, bubble sort, quick sort, heap sort and insert sort algorithm</li>
<li>Implements count, walk items, reverse walk items, for_all and rfor_all</li>
</ul>
<h4 id="thenetworklibrary">The network library</h4>
<ul>
<li>Implements dns(cached)</li>
<li>Implements ssl(openssl, polarssl, mbedtls)</li>
<li>Implements http</li>
<li>Implements cookies</li>
<li>Supports ipv4, ipv6</li>
<li>Supports coroutine</li>
</ul>
<h4 id="theplatformlibrary">The platform library</h4>
<ul>
<li>Implements timer, fast and low precision timer</li>
<li>Implements atomic and atomic64 operation</li>
<li>Implements spinlock, mutex, event, semaphore, thread and thread pool </li>
<li>Implements file, socket operation</li>
<li>Implements poller using epoll, poll, select, kqueue ...</li>
<li>Implements switch context interfaces for coroutine</li>
</ul>
<h4 id="thecharsetlibrary">The charset library</h4>
<ul>
<li>Supports utf8, utf16, gbk, gb2312, uc2 and uc4</li>
<li>Supports big endian and little endian mode</li>
</ul>
<h4 id="theziplibrary">The zip library</h4>
<ul>
<li>Supports gzip, zlibraw, zlib formats using the zlib library if exists</li>
<li>Implements lzsw, lz77 and rlc algorithm</li>
</ul>
<h4 id="theutilslibrary">The utils library</h4>
<ul>
<li>Implements base32, base64 encoder and decoder</li>
<li>Implements assert and trace output for the debug mode</li>
<li>Implements bits operation for parsing u8, u16, u32, u64 data</li>
</ul>
<h4 id="themathlibrary">The math library</h4>
<ul>
<li>Implements random generator</li>
<li>Implements fast fixed-point calculation, Supports 6-bits, 16-bits, 30-bits fixed-point number</li>
</ul>
<h4 id="thelibclibrary">The libc library</h4>
<ul>
<li>Implements lightweight libc library interfaces, the interface name contains <code>tb_xxx</code> prefix for avoiding conflict</li>
<li>Implements strixxx strrxxx wcsixxx wcsrxxx interface extension</li>
<li>Optimizes some frequently-used interface, .e.g. memset, memcpy, strcpy ... </li>
<li>Implements <code>memset_u16</code>, <code>memset_u32</code>, <code>memset_u64</code> extension interfaces</li>
</ul>
<h4 id="thelibmlibrary">The libm library</h4>
<ul>
<li>Implements lightweight libm library interfaces, the interface name contains <code>tb_xxx</code> prefix for avoiding conflict</li>
<li>Supports float and double type</li>
</ul>
<h4 id="theregexlibrary">The regex library</h4>
<ul>
<li>Supports match and replace</li>
<li>Supports global/multiline/caseless mode</li>
<li>Uses pcre, pcre2 and posix regex modules</li>
</ul>
<h4 id="thehashlibrary">The hash library</h4>
<ul>
<li>Implements crc32, adler32, md5 and sha1 hash algorithm</li>
<li>Implements some string hash algorithms (.e.g bkdr, fnv32, fnv64, sdbm, djb2, rshash, aphash ...)</li>
<li>Implements uuid generator</li>
</ul>
<h2 id="projects">Projects</h2>
<p>Some projects using tbox:</p>
<ul>
<li><a href="https://github.com/tboox/gbox">gbox</a></li>
<li><a href="https://github.com/tboox/vm86">vm86</a></li>
<li><a href="http://www.xmake.io">xmake</a></li>
<li><a href="https://github.com/tboox/itrace">itrace</a></li>
<li><a href="https://github.com/tboox/tbox/wiki/tbox-projects">more</a></li>
</ul>
<h2 id="build">Build</h2>
<p>Please install xmake first: <a href="https://github.com/xmake-io/xmake">xmake</a></p>
<pre><code class="lang-console"># build for the host platform
$ cd ./tbox
$ xmake

# build for the mingw platform
$ cd ./tbox
$ xmake f -p mingw --sdk=/home/mingwsdk 
$ xmake

# build for the iphoneos platform
$ cd ./tbox
$ xmake f -p iphoneos 
$ xmake

# build for the android platform
$ cd ./tbox
$ xmake f -p android --ndk=xxxxx
$ xmake

# build for the linux cross-platform
$ cd ./tbox
$ xmake f -p linux --sdk=/home/sdk # --bin=/home/sdk/bin
$ xmake
</code></pre>
<h2 id="example">Example</h2>
<pre><code class="lang-c">#include "tbox/tbox.h"

int main(int argc, char** argv)
{
    // init tbox
    if (!tb_init(tb_null, tb_null)) return 0;

    // trace
    tb_trace_i("hello tbox");

    // init vector
    tb_vector_ref_t vector = tb_vector_init(0, tb_element_cstr(tb_true));
    if (vector)
    {
        // insert item
        tb_vector_insert_tail(vector, "hello");
        tb_vector_insert_tail(vector, "tbox");

        // dump all items
        tb_for_all (tb_char_t const*, cstr, vector)
        {
            // trace
            tb_trace_i("%s", cstr);
        }

        // exit vector
        tb_vector_exit(vector);
    }

    // init stream
    tb_stream_ref_t stream = tb_stream_init_from_url("http://www.xxx.com/file.txt");
    if (stream)
    {
        // open stream
        if (tb_stream_open(stream))
        {
            // read line
            tb_long_t size = 0;
            tb_char_t line[TB_STREAM_BLOCK_MAXN];
            while ((size = tb_stream_bread_line(stream, line, sizeof(line))) >= 0)
            {
                // trace
                tb_trace_i("line: %s", line);
            }
        }

        // exit stream
        tb_stream_exit(stream);
    }

    // wait 
    getchar();

    // exit tbox
    tb_exit();
    return 0;
}
</code></pre>
<h2 id="contacts">Contacts</h2>
<ul>
<li>Email：<a href="mailto:waruqi@gmail.com">waruqi@gmail.com</a></li>
<li>Homepage：<a href="https://tboox.org">tboox.org</a></li>
<li>Community：<a href="https://www.reddit.com/r/tboox/">/r/tboox on reddit</a></li>
</ul>
</article>
</body>
</html>